package com.company.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class DatabaseUtil {
    public static SqlSessionFactory sqlSessionFactory;

    static {
        try {
            String resourse = "mybatis-config.xml";
            Reader reader = Resources.getResourceAsReader(resourse);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }

    public static SqlSession getSession() {
        return sqlSessionFactory.openSession();
    }
}
